﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ClipperBaseUI.Controls;

namespace Clipper.DataManage
{
    /// <summary>
    /// WinVarietyInput.xaml 的交互逻辑
    /// </summary>
    public partial class WinVarietyInput : BaseWindow
    {
        public WinVarietyInput()
        {
            InitializeComponent();
        }
        private Model.DetectVariety mModel=null;
        private void BaseWindow_Loaded(object sender, RoutedEventArgs e)
        {
            if (BaseServiceProvider.InputName == Model.InputEnum.Update)
            {
                Model.DetectVariety model = BaseServiceProvider.DataModel as Model.DetectVariety;
                if (model != null)
                {
                    mModel = model;
                    DataContext = model;
                }
            }
        }
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            bool result = true;
            if (Check())
            {
                Model.DetectVariety model = new Model.DetectVariety();
                BLL.DetectVariety bll = new BLL.DetectVariety();
                if (mModel != null)
                    model.itemTypeID = mModel.itemTypeID;
                model.typeName = txtTypeName.Text;
                model.OrderNumber = txtOrder.Number;
                model.IsShow = radShow.IsChecked.Value;
                if (BaseServiceProvider.InputName == Model.InputEnum.Add)
                {
                    result = bll.Add(model);
                }
                else
                {
                    result = bll.Update(model);
                }
                this.DialogResult = result;
            }
        }
        private bool Check()
        {
            List<string> strErr = new List<string>();

            if (string.IsNullOrEmpty(txtTypeName.Text))
            {
                strErr.Add("VarietyNameNotNullTip");   //类别名称不能为空！\n
            }
            if (string.IsNullOrEmpty(txtOrder.Text))
            {
                strErr.Add("OrderNumberNotNullTip");
            }
            if (strErr.Count>0)
            {
                UIHelper.ShowKeyMessage(strErr);
                return false;
            }

            return true;

        }
        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = null;
            this.Close();
        }

        
    }
}
